/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Button, Text, TextArea, useToast,} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl} from "../../common/base";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {EditStorageContext} from "../../StorageContext";
import {config资料审查, itemA上次问题,} from "./MaterialReview";
import {itemA下结论} from "../editorDJ";
import {itemA检验项} from "./AppendixPage";
import {itemA安全附件, itemA液面计} from "./Accessories";
import {checkConfig真空, checkConfig腐蚀} from "./AddonTest";

export const config设备概况 = [
    [['设备名称', '_$设备名称'], ['检验类别', '_$检验类别',],  ],
    [['设备代码','_$设备代码'], ['单位内编号','_$单位内部编号'], ],
    [['使用登记证编号', '_$使用证号'],  ],
    [['制造单位', '_$制造单位'],  ],
    [['使用单位', '_$使用单位'], ],
    [['使用单位地址', '_$使用单位地址'],  ],
    [['使用单位组织机构代码','_$使用单位信用码'], ['安全管理人员', '安全员'] ],
    [['联系电话', '安全员电'], ['设计使用年限','_$设计年限', '年'], ],
    [['投入使用日期', '_$投用日期'], ['上次检验日期', {n:'上次定检日期',t:'d'},], ],
    [['主体结构型式','_$主体结构'], ['运行状态','_$运行状态'] ],
    //orc.是换热? '换热面积':'容积'}
    [['容积', '_$容积换热', 'm³'], ['内径', '_$内径','mm'],  ],
    //几个类似的**介质 ？工作介质
    [['设计压力', '_$设计压力', 'MPa'], ['介质', '_$工作介质',],  ],
    //容器的温度字段太多了：就缺没有”设计温度“； # 允许充装量 =  (pa?.充重);
    [['设计温度',{n:'设计温', u:'℃'}], ['最大充装量','_$允许充装量', 'kg'], ],
];
/**开启编制时的：默认值初始化操作。  若打印：本编辑器全部都不显示。
 * */
export const EntranceSetup =
React.forwardRef((
    {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
) => {
    const atPrint = useMedia('print');
    const toast = useToast();
    const doCheckNames = React.useCallback((verId: string) => {
        const result = assertNamesUnique([{value: rep?.tzFields},
            {value: config设备概况, type:'esnt'}, {value: config资料审查, type:'esnt'},
            {value:[...itemA下结论, ...itemA上次问题, ...itemA检验项, ...itemA安全附件, ...itemA液面计 ]},
            {value: checkConfig真空, type:'s2Lu'},  {value: checkConfig腐蚀, type:'s2Lu'},
            {value:['Projects', ]} ]);
        toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
    }, [rep,toast]);
    const {storage, setStorage} =React.useContext(EditStorageContext) as any;
    const getInpFilter = React.useCallback((par: any) => {
        const {_tblFixed, } =par||{};
        return {_tblFixed, };
    }, []);
    const {inp, setInp} = useItemInputControl({ref});
    if (atPrint) return null;
    else return (
        <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                             alone={alone} label={'初始化本报告，默认值配置等'}>
            {process.env.REACT_APP_TEST==='true' && <><div>
                <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                <Text variant="h5">设置待测试表格的各列宽度：</Text>
                <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                    JSON.parse(e.currentTarget.value??'[]');
                    setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
            </div>
            </>
            }
            <hr/>
        </InspectRecordLayout>
    );
});

//有些分项模板真还没有做模板的：？ ：”安全阀校验报告“
export const Projects默认 = [
    {name: '移动式压力容器年度检验结论报告', do: true, ha: 'Conclusion'},
    {name: '移动式压力容器资料审查报告', do: true, ha: 'MaterialReview'},
    {name: '容器年度检验报告附页', ml: '移动式压力容器年度检验报告附页', ha: 'AppendixPage'},
    {name: '壁厚测定报告', ha: 'rp_thickm_'},
    {name: '壁厚校核报告', ha: ''},
    {name: '射线检测报告', ha: 'rp_radio_'},
    {name: '超声波检测报告', ha: 'rp_sonic_'},
    {name: '磁粉检测报告', ha: 'rp_magnetic_'},
    {name: '渗透检测报告', ha: 'rp_permeation_'},
    {name: '光谱分析报告', ha: 'rp_spectrVs_'},
    {name: '硬度检测报告', ha: 'rp_hardness_'},
    {name: '金相分析报告', ha: ''},
    {name: '安全附件检验报告', ha: 'Accessories'},
    {name: '安全阀校验报告', ha: ''},
    {name: '耐压试验报告', ha: 'rp_magnetic_'},
    {name: '气密性试验报告', ha: 'rp_gasproof_'},
    {name: '附加检验报告', ha: 'AddonTest'},
];
